define(['./../../initial'], function() {
    var app = angular.module('App.home');
    app.factory('webSocketEmitter', ['$rootScope',
        function($rootScope) {
            //service 返回的方法
            return (function() {
                function sendCmd(To, cmdName, para) {
                    var cmd = {
                        Command: cmdName,
                        Para: para,
                        Target: To
                    };
                    return cmd;
                }
                var obj = {
                    GetProjects: function() {
                        $rootScope.Socket.emit('GetProjects', '');
                    },
                    SelectProject: function(surveyPrjName) {
                        var nameList = [];
                        nameList.push(surveyPrjName); //直接发送名称
                        $rootScope.Socket.emit('SelectProject', nameList);
                    },
                    GetAllPoints: function(prjName) {
                        $rootScope.Socket.emit('Command', sendCmd(prjName, 'GetAllPoints', ''));
                    },
                    StartSurvey: function(prjName, array) {
                        array = array || '123';
                        $rootScope.Socket.emit('Command', sendCmd(prjName, 'StartSurvey', array));
                    },
                    StopSurvey: function(prjName) {
                        $rootScope.Socket.emit('Command', sendCmd(prjName, 'StopSurvey', ''));
                    }
                };
                return obj;
            })();

        }
    ]);
});
